import { _decorator, Component, Node } from 'cc';
import { Block } from './Block';
import { LevelType } from './type';
import { GAME_STATUS_ENUM } from './Enum';
const { ccclass, property } = _decorator;

@ccclass('DataManager')
export class DataManager extends Component {
    private static _instance: any = null;

    static getInstance<T>(): T {
        if (this._instance === null) {
            this._instance = new this();
        }
        return this._instance;
    }
    static get instance() {
        return this.getInstance<DataManager>();
    }

    _level: number = 1; //关卡
    blocks: Block[] = [];   //所有block
    records: Block[] = [];  //记录块(入槽)
    currentLevel: LevelType = null; //当前关卡数据
    gameStatus: GAME_STATUS_ENUM = GAME_STATUS_ENUM.INIT; //游戏状态
    clickable: boolean = false;

    public get level() {
        return this._level;
    }

    public set level(data: number) {
        this._level = data;
        this.save();
    }

    //初始化数据
    reset() {
        this.blocks = [];
        this.records = [];
        this.currentLevel = null;
        this.gameStatus = GAME_STATUS_ENUM.INIT;
        this.clickable = false;
    }

    //保存数据
    save() {

    }

    //读取数据
    resotre() {

    }
}


